HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/dashboard.orbiwheels.com/vendor/cuyz/valinor/src/Mapper/Source/Modifier/Mapping.php
<?php

declare(strict_types=1);

namespace CuyZ\Valinor\Mapper\Source\Modifier;

/** @internal */
final class Mapping
{
    /** @var array<string> */
    private array $keys;

    private string $to;

    private int $depth;

    /**
     * @param array<string> $keys
     */
    public function __construct(array $keys, string $to)
    {
        $this->keys = $keys;
        $this->to = $to;
        $this->depth = count($keys) - 1;
    }

    public function matches(int|string $key, int $atDepth): bool
    {
        $from = $this->keys[$atDepth] ?? null;

        return $from === (string)$key || $from === '*';
    }

    public function findMappedKey(int|string $key, int $atDepth): ?string
    {
        if ($atDepth < $this->depth
            || !$this->matches($key, $atDepth)
        ) {
            return null;
        }

        return $this->to;
    }
}